package jike.demo07;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: oop思想训练,不提供set方法是为了避免外部代码修改里边具体的属性值
 * @date 2022/10/26 21:28
 */
public class ShoppingCart {

    private int itemsCount;

    private double totalPrice;

    private List<ShoppingCart> cartList;


    /**
     * 定义一个初始化构造方法避免使用set方法来污染里边具体的属性
     */
    public ShoppingCart(int itemsCount, double totalPrice,List<ShoppingCart> cartList) {
        this.itemsCount = itemsCount;
        this.totalPrice = totalPrice;
        this.cartList = cartList;
    }


    public int getItemsCount() {
        return itemsCount;
    }

    public double getTotalPrice() {
        return totalPrice;
    }


    public void addItems(ShoppingCart cart) {
        cartList.add(cart);
        itemsCount++;
        totalPrice += cart.getTotalPrice();
    }

    /**
     * 定义清空的方法
     */
    public void clear(){
        this.itemsCount = 0;
        this.totalPrice = 0.0;
        cartList.clear();
    }

    /**
     * 查看购物车里面都买了啥
     */
    public List<ShoppingCart> getCartList(){
        return Collections.unmodifiableList(this.cartList);
    }



}
